package com.boang.fx;

import java.util.ArrayList;
import java.util.Iterator;

/*
  @author: 13813
  @date: 2024/11/28 16:39
*/
public class ArrayListDemo02 {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student());
        list3(students);

        ArrayList<Programmer> programmers = new ArrayList<>();
        programmers.add(new Programmer());
//        list3(programmers);
    }

    //下限  ? extends super Student 接收 Student 或 Student 父类对象
    public static void list3(ArrayList<? super Student> list) {
        Iterator<?> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }

    //上限  ? extends Person 接收 Person 或 Person 子类对象
    public static void list2(ArrayList<? extends Person> list) {
        Iterator<?> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }

    //? 通配符
    public static void list(ArrayList<?> list) {
        Iterator<?> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}
